added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSEFEntityDataModel / TablePerHierarchy / TPHClass.cs
blobeaf94f0aac4a4b76e806e423ef2ff113e6c82f66
1 /****************************** Module Header ******************************\
2 * Module Name: TPHClass.cs
3 * Project: CSEFEntityDataModel
4 * Copyright (c) Microsoft Corporation.
6 * This example demonstrates how to establish table per hierarchy inheritance.
7 * A table-per-type model is a way to model inheritance where each entity is
8 * mapped to a distinct table in the store. Then it shows how to query a list
9 * of people, get the corresponding properties of Person, Student and
10 * BusinessStudent.
12 * This source is subject to the Microsoft Public License.
13 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
14 * All other rights reserved.
16 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
17 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
19 \***************************************************************************/
21 #region Using directives
22 using System;
23 using System.Collections.Generic;
24 using System.Linq;
25 using System.Text;
26 #endregion
29 namespace CSEFEntityDataModel.TablePerHierarchy
31 public static class TPHClass
33 // Test the query method in TPHClass
34 public static void TPHTest()
36 Query();
39 // Query a list of people, print out the properties of Person,
40 // Student and BusinessStudent
41 public static void Query()
43 using (EFTPHEntities context = new EFTPHEntities())
45 var people = from p in context.People
46 select p;
48 foreach (var p in people)
50 Console.WriteLine("Student {0} {1}",
51 p.LastName,
52 p.FirstName);
54 if (p is Student)
56 Console.WriteLine("EnrollmentDate: {0}",
57 ((Student)p).EnrollmentDate);
59 if (p is BusinessStudent)
61 Console.WriteLine("BusinessCredits: {0}",
62 ((BusinessStudent)p).BusinessCredits);